package com.bjsxt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.AdminAddress;
import com.bjsxt.model.Result;
import com.bjsxt.service.AdminAddressService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * description:
 * 平台钱包归集地址控制层
 * TODO: 这里在进行权限配置的时候可能没有对应的权限，以后后期需要统一进行添加
 *
 * @author ALIENWARE
 * @version v1.0.0
 * @create 2/27/2024
 **/
@RestController
@RequestMapping("/adminAddress")
@Api(tags = "平台钱包归集地址控制器")
public class AdminAddressController {

    /**
     * 平台钱包归集地址业务层
     */
    @Autowired
    private AdminAddressService adminAddressService;

    /**
     * 分页查询平台钱包归集地址
     *
     * @param page 分页对象<AdminAddress>
     * @param id   平台归账手续费等账户 ID
     * @return 统一响应对象
     */
    @GetMapping
//    @PreAuthorize("hasAuthority('trade_coin_type_query')")
    @ApiOperation(value = "分页查询平台钱包归集地址", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20"),
            @ApiImplicitParam(name = "id", value = "ID", dataType = "Long", paramType = "query", example = "1")
    })
    public Result<Page<AdminAddress>> findByPage(@ApiIgnore Page<AdminAddress> page, Long id) {
        // 调用业务层进行数据的查询
        Page<AdminAddress> adminAddressPage = adminAddressService.pageById(page, id);
        // 返回响应数据
        return Result.success(adminAddressPage);
    }

    /**
     * 增加一个钱包归集地址
     *
     * @param adminAddress 钱包归集地址添加数据对象
     * @return 统一响应对象
     */
    @PostMapping
//    @PreAuthorize("hasAuthority('trade_coin_type_create')")
    @ApiOperation(value = "增加一个钱包归集地址", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminAddress", value = "AdminAddress 的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> add(@Validated @RequestBody AdminAddress adminAddress) {
        // 调用业务层方法进行数据的保存
        boolean flag = adminAddressService.addAdminAddress(adminAddress);
        // 如果为 true 新增成功
        if (flag) return Result.success("新增成功");
        // 如果为 false 新增失败
        return Result.fail("新增失败");
    }

    /**
     * 对一个钱包归集地址进行更新操作
     *
     * @param adminAddress 钱包归集地址修改数据对象
     * @return 统一响应对象
     */
    @PatchMapping
//    @PreAuthorize("hasAuthority('trade_coin_type_update')")
    @ApiOperation(value = "修改一个钱包归集地址", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminAddress", value = "AdminAddress 的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> update(@Validated @RequestBody AdminAddress adminAddress) {
        // 调用业务层方法进行数据的更新
        boolean flag = adminAddressService.updateById(adminAddress);
        // 如果为 true 更新成功
        if (flag) return Result.success("修改成功");
        // 如果为 false 更新失败
        return Result.fail("修改失败");
    }
}
